<?php

namespace app\index\controller;

use app\api\controller\Basic;

class Receive extends Basic
{

    /*
    * 云信消息抄送接口
    */
    public function receiveMsg()
    {
        $body = @file_get_contents('php://input');
        $data = json_decode($body, true);         // 值得注意 true
        //file_put_contents('/debug.txt',$body); // 测试有没有接收到数据，很实用哦
        dump($data);
        if ($data) {
            $d['eventType']       = $data['eventType'];
            $d['attach']          = $data['attach'];
            $d['body']            = empty($data['body']) ? '' : $data['body'];
            $d['convType']        = empty($data['convType']) ? '' : $data['convType'];
            $d['fromDeviceId']    = empty($data['fromDeviceId']) ? '' : $data['fromDeviceId'];
            $d['msgidServer']     = empty($data['msgidServer']) ? '' : $data['msgidServer'];
            $d['ext']             = empty($data['ext']) ? '' : $data['ext'];
            $d['fromAccount']     = $data['fromAccount'];
            $d['fromAvator']      = empty($data['fromAvator']) ? '' : $data['fromAvator'];
            $d['fromClientType']  = $data['fromClientType'];
            $d['fromExt']         = empty($data['fromExt']) ? '' : $data['fromExt'];
            $d['fromNick']        = $data['fromNick'];
            $d['msgTimestamp']    = $data['msgTimestamp'];
            $d['msgType']         = $data['msgType'];
            $d['msgidClient']     = $data['msgidClient'];
            $d['resendFlag']      = $data['resendFlag'];
            $d['roleInfoTimetag'] = empty($data['roleInfoTimetag']) ? '' : $data['roleInfoTimetag'];
            $d['customSafeFlag']  = empty($data['customSafeFlag']) ? '' : $data['customSafeFlag'];
            $d['roomId']          = empty($data['roomId']) ? '' : $data['roomId'];
            $d['antispam']        = empty($data['antispam']) ? '' : $data['antispam'];
            
            $info = $this->insertTable('receivemsg', $d);
            if ($info) {
                echo 200;   // 要有返回值 200 没有200 云信会在此的发送 具体看说明文档
            }
        } else {
            echo 500;
        }
    }
}
